{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Azure_API使用风险分析"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "测试内容：\n",
    "\n",
    "* 一、模糊程度\n",
    "* 二、黑白照片\n",
    "* 三、残缺不全"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 一、 模糊程度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['indoor', 'book', 'shelf', 'bookshelf', 'cluttered']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "import matplotlib.pyplot as plt\n",
    "import json\n",
    "from PIL import Image\n",
    "from io import BytesIO\n",
    "import demjson\n",
    "import pandas as pd \n",
    "\n",
    "# Replace <Subscription Key> with your valid subscription key.\n",
    "subscription_key = \"my_key\"\n",
    "assert subscription_key\n",
    "\n",
    "vision_base_url = \"http://api.cognitive.azure.cn/vision/v1.0/\"\n",
    "\n",
    "analyze_url = vision_base_url + \"tag\"\n",
    "\n",
    "# Set image_url to the URL of an image that you want to analyze.\n",
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-7b6901449fba15c3.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key }\n",
    "params  = {'visualFeatures': 'Categories,Description,Color'}\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "\n",
    "analysis = response.json()\n",
    "\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "name = [x['name'] for x in text['tags']]\n",
    "name"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![book](https://upload-images.jianshu.io/upload_images/14204282-7b6901449fba15c3.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['book', 'shelf', 'indoor']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-884430edf6861553.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "name2 = [x['name'] for x in text['tags']]\n",
    "name2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![book_h](https://upload-images.jianshu.io/upload_images/14204282-884430edf6861553.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['indoor', 'bed', 'blur']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-90845004fc406f3f.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "name3 = [x['name'] for x in text['tags']]\n",
    "name3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![book_h](https://upload-images.jianshu.io/upload_images/14204282-90845004fc406f3f.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 小结：模糊的照片会对识别个数以及识别准确率带来一定程度的影响\n",
    "* 解决方法：在进行识别之前，浮现提示语，提醒用户尽量保持平稳拍摄。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 二、黑白照片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['book', 'shelf', 'indoor', 'bookshelf', 'stack', 'cluttered']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-cd1bc951434d0410.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "name4 = [x['name'] for x in text['tags']]\n",
    "name4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![black_white](https://upload-images.jianshu.io/upload_images/14204282-cd1bc951434d0410.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 小结：黑白照片并不影响识别效果"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三、残缺不全\n",
    "* 人脸\n",
    "    * 完整\n",
    "    * 左半边脸\n",
    "    * 下半边脸\n",
    "    * 额头\n",
    "* 物体\n",
    "    * 完整\n",
    "    * 半个\n",
    "        * 上半个\n",
    "        * 下半个\n",
    "    * 三分之一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['person']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#人_完整\n",
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-18eb99afb29f83aa.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "person1 = [x['name'] for x in text['tags']]\n",
    "person1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![person1](https://upload-images.jianshu.io/upload_images/14204282-18eb99afb29f83aa.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['person', 'indoor', 'young', 'posing', 'staring']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 人_右脸\n",
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-bedfabe5dc878c7a.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "person2 = [x['name'] for x in text['tags']]\n",
    "person2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![person2](https://upload-images.jianshu.io/upload_images/14204282-bedfabe5dc878c7a.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['person']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#人_下半边脸\n",
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-6f59f8b7cf8d62ce.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "person3 = [x['name'] for x in text['tags']]\n",
    "person3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![person3](https://upload-images.jianshu.io/upload_images/14204282-6f59f8b7cf8d62ce.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['person', 'blurry']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#人_额头\n",
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-846c974b628da74e.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "person4 = [x['name'] for x in text['tags']]\n",
    "person4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![person4](https://upload-images.jianshu.io/upload_images/14204282-846c974b628da74e.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['wall', 'indoor']"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 物体_完整_太近了未能准确识别出来\n",
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-48c03c624ea2e144.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "object1 = [x['name'] for x in text['tags']]\n",
    "object1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![object1](https://upload-images.jianshu.io/upload_images/14204282-48c03c624ea2e144.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['knife']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#  物体_刀_完整\n",
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-95de65044448205f.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "object2 = [x['name'] for x in text['tags']]\n",
    "object2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![object2](https://upload-images.jianshu.io/upload_images/14204282-95de65044448205f.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'name'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mget_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m   3077\u001b[0m             \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3078\u001b[0;31m                 \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   3079\u001b[0m             \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;31mKeyError\u001b[0m: 'name'",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-24-e50dcd0edb4f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     10\u001b[0m \u001b[0;31m# 大数据模块 pandas 简化输出\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     11\u001b[0m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'tags'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'name'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     13\u001b[0m \u001b[0;31m#列表推导\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m \u001b[0mobject3\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'name'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtext\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'tags'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m   2686\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getitem_multilevel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2687\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2688\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getitem_column\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2689\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2690\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m_getitem_column\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36m_getitem_column\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m   2693\u001b[0m         \u001b[0;31m# get column\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2694\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_unique\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2695\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_item_cache\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2696\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2697\u001b[0m         \u001b[0;31m# duplicate columns & possible reduce dimensionality\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m_get_item_cache\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m   2487\u001b[0m         \u001b[0mres\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcache\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2488\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mres\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2489\u001b[0;31m             \u001b[0mvalues\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2490\u001b[0m             \u001b[0mres\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_box_item_values\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalues\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2491\u001b[0m             \u001b[0mcache\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mres\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/internals.py\u001b[0m in \u001b[0;36mget\u001b[0;34m(self, item, fastpath)\u001b[0m\n\u001b[1;32m   4113\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4114\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misna\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4115\u001b[0;31m                 \u001b[0mloc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   4116\u001b[0m             \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4117\u001b[0m                 \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0misna\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mget_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m   3078\u001b[0m                 \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3079\u001b[0m             \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3080\u001b[0;31m                 \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   3081\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3082\u001b[0m         \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;31mKeyError\u001b[0m: 'name'"
     ]
    }
   ],
   "source": [
    "#  物体_刀_上半个_识别失败\n",
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-c6675eae3cb29da3.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "object3 = [x['name'] for x in text['tags']]\n",
    "object3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![object3](https://upload-images.jianshu.io/upload_images/14204282-c6675eae3cb29da3.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['knife', 'weapon']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#  物体_刀_下半个\n",
    "image_url = \"https://upload-images.jianshu.io/upload_images/14204282-c7486c4dbafd3442.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\"\n",
    "data    = {'url': image_url}\n",
    "response = requests.post(analyze_url, headers=headers, params=params, json=data)\n",
    "response.raise_for_status()\n",
    "analysis = response.json()\n",
    "data = demjson.encode(response.json())\n",
    "text = demjson.decode(data)\n",
    "# data['pois']是列表，含关键字搜索结果\n",
    "# 大数据模块 pandas 简化输出 \n",
    "df = pd.DataFrame(text['tags'])\n",
    "df['name']\n",
    "#列表推导\n",
    "object3 = [x['name'] for x in text['tags']]\n",
    "object3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![object4](https://upload-images.jianshu.io/upload_images/14204282-c7486c4dbafd3442.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 小结：在识别人方面准确率很高，但在物体上如果物体离镜头过近、角度问题、或是没有拍摄出物体的基本特征就会导致识别错误或是识别不准确。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 总结：\n",
    "* 黑白照片不影响识别结果（不涉及灰度）\n",
    "* 模糊的照片会对识别个数以及识别准确率带来一定程度的影响\n",
    "* 在识别人的方面准确率较高，但物体上如果物体离镜头过近、角度问题、或是没有拍摄出物体的基本特征就会导致识别错误或是识别不准确。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 改进方法：\n",
    "* 在进行识别之前，浮现提示语，提醒用户尽量保持平稳拍摄，并提示用户将检测物体的基本特征完整的拍摄出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
